package tmp.Chlid;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;


public class Test {
	public static Map<String, Integer> numMap=new HashMap<String, Integer>();
	public static void main(String[] args) throws SQLException {
		
		Connection con=DAO.DbcpConnection.getConnection();
		String sql="select * from all_detail_total where word=0";
		Statement st=con.createStatement();
		ResultSet rs=st.executeQuery(sql);
		while (rs.next()) {
			String style=rs.getString("style");
			String imagepath=rs.getString("imagepath");
			int word=rs.getInt("word");
			addNum(style,imagepath,word);
		}
		
		
		
		for (Iterator iterator = numMap.keySet().iterator(); iterator.hasNext();) {
			String style = (String) iterator.next();
			System.out.println(style+":"+numMap.get(style));
			
		}
	}
	private static void addNum(String style, String imagepath, int word) {
		if(style!=null){
		int imagenum=getnum(imagepath);
		int k;
		if(numMap.get(style)==null){
			k=0;
		}
		Integer kIn=numMap.get(style);
		if(kIn==null){
			k=0;
		}else{
			k=kIn;
		}
		
		k+=imagenum;
		numMap.put(style, k);
		}
	}
	private static int getnum(String imagepath) {
		if(imagepath==null){
			return 0;
		}
		String[] images=imagepath.split("\\|");
		int k=0;
		for (int i = 0; i < images.length; i++) {
			String string = images[i];
			if(string.length()>5){
				k++;
			}
		}
		return k;
	}
}
